package com.ruoyi.deeplearn.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.deeplearn.domain.DeepForecastResult;
import com.ruoyi.deeplearn.service.IDeepForecastResultService;
import com.ruoyi.gis.service.IGisLayerService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.deeplearn.domain.DeepForecast;
import com.ruoyi.deeplearn.service.IDeepForecastService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 模型预测Controller
 *
 * @author rww
 * @date 2024-09-14
 */
@RestController
@RequestMapping("/deeplearn/forecast")
public class DeepForecastController extends BaseController
{
    @Autowired
    private IDeepForecastService deepForecastService;
    @Autowired
    private IGisLayerService gisLayerService;
    @Autowired
    private IDeepForecastResultService deepForecastResultService;

    /**
     * 查询模型预测列表
     */
//    @PreAuthorize("@ss.hasPermi('deeplearn:forecast:list')")
    @GetMapping("/list")
    public TableDataInfo list(DeepForecast deepForecast)
    {
        startPage();
        deepForecast.setType(DeepForecast.type_user);
        List<DeepForecast> list = deepForecastService.
                selectDeepForecastList(deepForecast);
        return getDataTable(list);
    }

    /**
     * 导出模型预测列表
     */
//    @PreAuthorize("@ss.hasPermi('deeplearn:forecast:export')")
    @Log(title = "模型预测", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DeepForecast deepForecast)
    {
        List<DeepForecast> list = deepForecastService.selectDeepForecastList(deepForecast);
        ExcelUtil<DeepForecast> util = new ExcelUtil<DeepForecast>(DeepForecast.class);
        util.exportExcel(response, list, "模型预测数据");
    }

    /**
     * 获取模型预测详细信息
     */
//    @PreAuthorize("@ss.hasPermi('deeplearn:forecast:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        DeepForecast forecast = deepForecastService.selectDeepForecastById(id);
        if(forecast ==null){
            return AjaxResult.error();
        }
        if(forecast.getLayerId()!=null){
            forecast.setLayer(gisLayerService.selectGisLayerByLayerId(forecast.getLayerId()));
        }
        if(forecast.getLastResultId()!=null){
            DeepForecastResult forecastResult = deepForecastResultService.
                    selectDeepForecastResultById(forecast.getLastResultId());
            forecast.setForecastResultLast(forecastResult);
        }
        return success(forecast);
    }

    /**
     * 新增模型预测
     */
//    @PreAuthorize("@ss.hasPermi('deeplearn:forecast:add')")
    @Log(title = "模型预测", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DeepForecast deepForecast)
    {
        return toAjax(deepForecastService.insertDeepForecast(deepForecast));
    }

    /**
     * 修改模型预测
     */
//    @PreAuthorize("@ss.hasPermi('deeplearn:forecast:edit')")
    @Log(title = "模型预测", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DeepForecast deepForecast)
    {
        return toAjax(deepForecastService.updateDeepForecast(deepForecast));
    }

    /**
     * 删除模型预测
     */
//    @PreAuthorize("@ss.hasPermi('deeplearn:forecast:remove')")
    @Log(title = "模型预测", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(deepForecastService.deleteDeepForecastByIds(ids));
    }
}
